package training;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_8_22_Training {
    //包含所有 1 的最小矩形面积 I
    public int minimumArea(int[][] grid) {
        int top = Integer.MAX_VALUE, left = Integer.MAX_VALUE, right = Integer.MIN_VALUE, buttom = Integer.MIN_VALUE;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if (grid[i][j] == 1) {
                    top = Math.min(top, i);
                    left = Math.min(left, j);
                    right = Math.max(right, j);
                    buttom = Math.max(buttom, i);
                }
            }
        }
        return (buttom - top + 1) * (right - left + 1);
    }
}
